/**
* Author: CZ (cz.devnet@gmail.com)
*
* Description:
 */

package utils

import (
	"net/smtp"
	"strings"
)

func init() {

}

var once bool = true

const (
	host_163   = "smtp.163.com"
	email_163  = "gotawork@163.com"
	passwd_163 = "work225306"

	host_qq   = "smtp.qq.com"
	email_qq  = "350712378@qq.com"
	passwd_qq = "cgqqadeoitfgbidi"
)

func Mail(body string) error {
	var host, email, passwd string
	if once {
		host = host_163
		email = email_163
		passwd = passwd_163
		once = false
	} else {
		host = host_qq
		email = email_qq
		passwd = passwd_qq
		once = true
	}

	to := strings.Split("350712378@qq.com;278608029@qq.com;Joketang@icloud.com", ";")
	auth := smtp.PlainAuth("", email, passwd, host)

	var content_type string

	content_type = "Content-Type: text/plain" + "; charset=UTF-8"
	msg := []byte("To: " + "350712378@qq.com" + "\r\nFrom: " + email + "\r\nSubject: Finsur ICO" + "\r\n" + content_type + "\r\n\r\n" + body)
	//println(string(msg))
	Logger.Info("[MAIL]:" + string(msg))
	err := smtp.SendMail(host+":25", auth, email, to, msg)
	return err
}
